DodoRunner.AssetManager = (function(){
var
    observable = {},

    ready = false,

    images = [{
        "name"  : "ground",
        "url"   : "res/images/ground.png",
        "image" : undefined
    },
    {
        "name"  : "background",
        "url"   : "res/images/bg_sky.png",
        "image" : undefined
    },
    {
        "name"  : "dodo",
        "url"   : "res/images/dodo.png",
        "image" : undefined
    },
    {
        "name"  : "cloud_01",
        "url"   : "res/images/bg_cloud01.png",
        "image" : undefined
    },
    {
        "name"  : "cloud_02",
        "url"   : "res/images/bg_cloud02.png",
        "image" : undefined
    },
    {
        "name"  : "cloud_03",
        "url"   : "res/images/bg_cloud03.png",
        "image" : undefined
    },
    {
        "name"  : "air",
        "url"   : "res/images/air.png",
        "image" : undefined
    },
    {
        "name"  : "quad",
        "url"   : "res/images/quadrat.png",
        "image" : undefined
    },
    {
        "name"  : "triangle",
        "url"   : "res/images/triangle.png",
        "image" : undefined
    },
    {
        "name"  : "circle",
        "url"   : "res/images/circle.png",
        "image" : undefined
    },
    {
        "name"  : "ship",
        "url"   : "res/images/ship.png",
        "image" : undefined
    }],

    init = function(){
        loadImages();
    },

    getImageByName = function(name){
        for(var i = 0, max = images.length; i < max; i++){
            if(images[i].name == name) return images[i].image;
        }
        return undefined;
    },

    checkLoaded = function(){
        if(ready) return;
        for(var i = 0, max = images.length; i < max; i++){
            if(images[i].image == undefined) return;
        }
        ready = true;
        $(observable).trigger("ready");
    },

    loadImages = function(){
        for(var i = 0, max = images.length; i < max; i++){
            images[i].image = new Image();
            images[i].image.onload = checkLoaded;
            images[i].image.src = images[i].url;
        }
    }

    return {
        init : init,
        getImageByName : getImageByName,
        on : function(event, callback){
            return $(observable).on(event, callback);
        }
    }

}());